import com.scfire.security.Authority
import com.scfire.security.Member
import com.scfire.security.MemberAuthority
import com.scfire.security.RequestMap
import com.scfire.festival.RedEnvelope
import com.scfire.project.MainCate

class BootStrap {

    def init = { servletContext ->
		
		println "bootstrap init starting......"
		
		//建立系统用户
		/*if(!Member.findByUsername("SYSTEM_OPEATOR_UNIQUE")){
			def sysInstance = new Member()
			sysInstance.username = "SYSTEM_OPEATOR_UNIQUE"
			sysInstance.password = "p@s4Vv0rd"
			sysInstance.mobile = "1234567890"
			sysInstance.save flush:true
		}
		
		//新建红包数据
		if(!RedEnvelope.get(1)){
			def tickets = new RedEnvelope();
			tickets.ticket = ""
			tickets.save(flush: true)
		}*/
		
		/*def requestMap = RequestMap.findAll()
		for(def req : requestMap){
			req.delete(flush:true)
		}
		
		//基础文件
		RequestMap.create('/js/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/css/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/images/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/frozen/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/config/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/error','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/assets/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/fonts/**','IS_AUTHENTICATED_ANONYMOUSLY',true)		
		RequestMap.create('/css_pc/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/img_pc/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//整体拦截
		RequestMap.create('/','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/**','ROLE_ADMIN,ROLE_USER',true)
		//首页权限放开
		RequestMap.create('/index/index','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/index/indexJSON','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/index/waiter','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//登陆模块权限放开
		RequestMap.create('/login/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/logout/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/register/**','IS_AUTHENTICATED_ANONYMOUSLY',true)		
		//微信模块权限放开
		RequestMap.create('/weixin/**','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//支付模块权限控制
		RequestMap.create('/pay/**','ROLE_ADMIN,ROLE_USER',true)
		RequestMap.create('/pay/callBack','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/pay/alipayExplain','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/pay/alipayOrder','IS_AUTHENTICATED_ANONYMOUSLY',true)
		
		RequestMap.create('/pay/alipayReturn','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/pay/alipayNotify','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//项目模块权限控制
		RequestMap.create('/project/**','ROLE_ADMIN,ROLE_USER',true)
		RequestMap.create('/project/projectList','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/project/imgRead','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//个人中心模块权限控制
		RequestMap.create('/user/**','ROLE_ADMIN,ROLE_USER',true)
		//付款模块  支付宝付款回调函数
		RequestMap.create('/pay/alipayNotify','permitAll',true)
		//管理模块权限控制
		RequestMap.create('/manage/**','ROLE_ADMIN',true)
		//捐赠证书权限控制
		RequestMap.create('/donate/donateElectronicInfo','IS_AUTHENTICATED_ANONYMOUSLY',true)
		//异常模块权限控制
		RequestMap.create('/errors/**','IS_AUTHENTICATED_ANONYMOUSLY',true)		
		//pc端
		RequestMap.create('/project/product','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/project/cases','IS_AUTHENTICATED_ANONYMOUSLY',true)
		RequestMap.create('/project/companion','IS_AUTHENTICATED_ANONYMOUSLY',true)*/
		//红包用户拦截
		//RequestMap.create('/index/festivalActivity','ROLE_ADMIN,ROLE_USER',true)
		
		/*def authorities = Authority.findAll()
		for(def auth : authorities){
			auth.delete(flush:true)
		}
		
		//权限设置
		Authority.create('ROLE_ADMIN',true)
		Authority.create('ROLE_USER',true)	*/	

		/*def adminInstance = Member.findByUsername("admin")
		adminInstance.username = "admin"
		adminInstance.password = "admin"
		adminInstance.save flush:true*/
		//def auth = Authority.findByAuthority("ROLE_ADMIN")
		/*if(!Member.findByUsername("admin")){
			 def adminInstance = new Member()
			 adminInstance.username = "admin"
			 adminInstance.password = "admin"
			 adminInstance.mobile = "15121044276"
			 adminInstance.save flush:true
			 def auth = Authority.findByAuthority("ROLE_ADMIN")
			 MemberAuthority.create(adminInstance, auth)
		}*/
		
		/*//初始化分类数据
		def mainCates = MainCate.findAll()
		for(def mainCate : mainCates){
			mainCate.delete(flush:true)
		}
		MainCate mc1 = new MainCate()
		mc1.name = "教育助学"
		mc1.code = "100001"
		mc1.save(flush:true)
		MainCate mc2 = new MainCate()
		mc2.name = "扶贫救灾"
		mc2.code = "100002"
		mc2.save(flush:true)
		MainCate mc3 = new MainCate()
		mc3.name = "疾病救助"
		mc3.code = "100003"
		mc3.save(flush:true)
		MainCate mc4 = new MainCate()
		mc4.name = "其它"
		mc4.code = "100004"
		mc4.save(flush:true)*/
		
		println "bootstrap init ending"
		
    }
    def destroy = {
    }
}
